﻿using ExcellentProject.Dominio.Cuestionarios.Entidades;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace ExcellentProject.Behaviors.Html
{
    public class ResourceQuestionRenderBehavior
        : IRenderBehavior<Pregunta>
    {
        public void RenderQuestion(System.Web.UI.WebControls.Panel panel, Pregunta question)
        {
            //Question Design 
            #region Statement label
            var statementLabel = new Label()
            {
                ID = "statementLabel",
                Text = question.Enunciado
            };
            panel.Controls.Add(statementLabel);
            #endregion

            #region Resource
            int resourceNumber = 1;
            foreach (var item in question.Recursos)
            {
                switch (item.CodigoTipo)
                {
                    case "SND":
                        var literalControlBuilder = new StringBuilder();
                        literalControlBuilder.Append("<audio controls>");
                        literalControlBuilder.Append("<source src=\"" + item.Uri +"\" type=\"audio/mpeg\">");
                        literalControlBuilder.Append("</audio>");
                        panel.Controls.Add(new LiteralControl(literalControlBuilder.ToString()));
                        break;
                    case "VID":
                        var videoControlBuilder = new StringBuilder();
                        videoControlBuilder.Append("<video width=\"320\" height=\"240\" controls>");
                        videoControlBuilder.Append("<source src=\"" + item.Uri + "\" type=\"video/mp4\">");
                        videoControlBuilder.Append("</video>");
                        panel.Controls.Add(new LiteralControl(videoControlBuilder.ToString()));
                        break;
                    default:
                        var imageControlBuilder = new StringBuilder();
                        imageControlBuilder.Append("<img width=\"320\" height=\"240\"");
                        imageControlBuilder.Append(" src=\"" + item.Uri + "\" t>");
                        imageControlBuilder.Append("</img>");

                        panel.Controls.Add(new LiteralControl(imageControlBuilder.ToString()));
                        break;
                }
                resourceNumber++;
            }
            #endregion

            #region Question Body
            panel.Controls.Add(new HtmlGenericControl("br"));
            int optionNumber = 1;

            foreach (var item in question.Opciones)
            {
                var option = new RadioButton()
                {
                    ID = "option" + optionNumber,
                    Text = item.Descripcion
                };
                panel.Controls.Add(option);
                panel.Controls.Add(new LiteralControl("<br />"));
            }
            #endregion
        }
    }
}